﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _3_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Truck truck = new Truck();

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int wheels = int.Parse(textBox1.Text);
                float weight = float.Parse(textBox2.Text);
                float maxLoad = float.Parse(textBox3.Text);
                float oilPerKm = float.Parse(textBox4.Text);

                truck.SetVehicle(wheels, weight, maxLoad, oilPerKm);
                MessageBox.Show("车辆信息设置成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            truck.GetVehicle();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                float nowLoad = float.Parse(textBox5.Text);
                bool isOverload = truck.Overload(nowLoad);

                if (isOverload)
                    MessageBox.Show("卡车超载！");
                else
                    MessageBox.Show("卡车不超载！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                float runKm = float.Parse(textBox6.Text);
                float oil = truck.OilConsumption(runKm);
                MessageBox.Show($"总耗油量: {oil}");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            truck.GetVehicle();
        }

       

        private void button4_Click_1(object sender, EventArgs e)
        {
            try
            {
                float runKm = float.Parse(textBox6.Text);
                float oil = truck.OilConsumption(runKm);
                MessageBox.Show($"总耗油量: {oil}");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            try
            {
                float nowLoad = float.Parse(textBox5.Text);
                bool isOverload = truck.Overload(nowLoad);

                if (isOverload)
                    MessageBox.Show("卡车超载！");
                else
                    MessageBox.Show("卡车不超载！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的数字！");
            }
        }
    }
}
